<template>
  <el-dialog
    v-if="open"
    class="dia-style"
    title="强制转派"
    :visible.sync="open"
    append-to-body
    width="30%"
    :close-on-click-modal="false"
    @close="cancel"
  >
    <hk-form
      ref="hkFormRef"
      :form-labels="formLabels"
      :rules="formRules"
      :data="formData"
      :btn-hidden="true"
      :dict-list="dictList"
      label-width="140"
      label-position="left"
    />
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="handleSubmit">确定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </el-dialog>
</template>
<script>
import HkForm from '@/components/Hk-Form/index.vue'
import { queryUserByOrderId, transfer } from '@/api/dispose/workbenchList.js'
export default {
  components: { HkForm },
  data() {
    return {
      open: false,
      formLabels: [
        {
          label: '运维主管',
          field: 'targetUserId',
          type: 'select',
          list: 'nameLists',
          span: 24,
          attrs: {
            placeholder: '请选择处理人'
          }
        },
        {
          label: '评论',
          field: 'content',
          type: 'textarea',
          attrs: {
            cols: 100,
            rows: 5
          },
          span: 24
        }
      ],
      dictList: {
        nameLists: []
      },
      formRules: {
        targetUserId: [{ required: true, message: '请选择', trigger: 'blur' }]
      },
      formData: {},
      serialNumber: null
    }
  },
  mounted() {
    // this.getUsers();
  },
  methods: {
    show(id, serialNumber) {
      this.open = true
      this.serialNumber = serialNumber
      this.getUsers(id)
    },
    cancel() {
      this.open = false
      this.$emit('handleCancel')
    },
    //  获取运维主管
    getUsers(id) {
      queryUserByOrderId({ orderId: id }).then((res) => {
        if (res.length > 0) {
          this.formLabels[0].label = res[0].nodeName
          this.dictList.nameLists = res[0].userProfileDtos.map((i) => {
            return { label: i.name, value: i.id }
          })
        }
      })
    },
    //  提交
    handleSubmit() {
      transfer({
        ...this.formData,
        serialNumber: this.serialNumber,
        transferType: 0
      }).then((res) => {
        this.$message.success('强制转派成功')
        this.cancel()
      })
    }
  }
}
</script>

<style lang="scss" scoped>
.content {
  padding: 20px 20px;
  font-weight: bold;
  i {
    font-size: 18px;
    color: #fa541c;
  }
}
.btn {
  text-align: right;
  padding-top: 20px;
}
</style>
